home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_08_09
/
8n09115a
< prev
next >
Wrap
Text File
|
1990-06-18
|
2KB
|
82 lines
*******
Listing 3:
double cvd(s)
char *s;
/* Function to read an 8 yte string*/
/* representing a BASIC floatwritten*/
/* by MKDS. Entry = string*/
/* Return = value*/
{
double sum;
double t, tt, div;
int cnt, exp, pos, n, negative;
sum = 0;
exp = s[7]; /*exponent*/
negative = s[6] & 0x80; /*Save signbit*/
s[6] = s[6] & 0x7f; /*Mask signbit*/
exp -= 0x81; /*Subtract offset*/
/* printf("\nExp:%d T:%4.4f",exp,t); */
sum += t;
cnt = 7;
div = 128.0;
pos = 8;
while (cnt--)
{
n=s[pos];
tt=t/div;
/* printf("\n&d : n 4.4f t-t4.4f tt=%d.df",pos,n,t,tt);*/
sum += tt*n;
div *= 256;
--pos;
}
if (negative)
sum = -sum;
return(sum);
}
double svs(s)
char *s;
/* Function to read a 4 byte string */
/* representing a BASIC float written */
/* by MKSS. Entry = string */
/* Return = value */
{
double sum;
double t, tt, div;
int cnt, exp, pos, n, negative;
sum = 0;
exp = s[3]; /*Exponent */
negative = s[2] & 0x80; /*Save signbit */
s[6] = s[2] & 0x7f; /*Mask */
exp -= 0x81; /*Subtract offset */
t = pow(2.0, (double) exp);
/* printf("\nExp:% t:%4.4f",exp,t); */
sum += t;
cnt = 3;
div = 128.0;
pos = 2;
while (cnt--)
{
n = s[pos];
tt = t / div;
/* printf("/\n%d : n=%4.4f t=%4.4f tt-%4.4f",pos,n,t,tt);*/
sum += tt * n;
div /= 128;
--pos;
}
if (negative)
sum = -sum;
return(sum);
}
********